<template>
  <div>
    <b-img
      :src="userImage"
      rounded="circle"
      center
      alt="Circle image"
      width="90%"
      thumbnail
      id="image"
    ></b-img>
    <p id="username">
      <b>游客{{ userCode }}</b>
    </p>
    <b-list-group>
      <b-list-group-item @click="toUser">用户管理</b-list-group-item>
      <b-list-group-item to="/scenery">景区列表</b-list-group-item>
      <b-list-group-item to="/travel">旅行社列表</b-list-group-item>
    </b-list-group>
  </div>
</template>

<script>
import userImage from "@/assets/user.jpg";
import bus from "@/components/eventBus";
export default {
  name: "Home",
  data() {
    return {
      userCode: "000001",
      userImage: userImage,
    };
  },
  props: [],
  created() {
    bus.$on("shareUser", (val) => {
      this.userCode = val.code;
    });
  },
  methods: {
    toUser() {
      const token = window.sessionStorage.getItem("user");
      if (token != null) {
        this.$router.push("/user/userinfo");
      } else {
        this.$router.push("/user/login");
      }
    },
  },
};
</script>

<style scoped>
#image {
  margin-top: 5px;
  margin-bottom: 5px;
}
#username {
  width: 100%;
  text-align: center;
  margin: 0 auto;
}
.list-group {
  margin: 2px;
}
</style>